home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
276-300
/
285
/
liner
/
source
/
menu.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-14
|
9KB
|
403 lines
#define ABOUT_Y_REG 42
#define ABOUT_Y_LACED 142
#define FP 1 /*Pen for filenames in YAFR (white)*/
#define DP 3 /* " " dirnames " " (orange)*/
NewAll() /*Get rid of all the Items*/
{
char Buffer[10];
FreeListMem(FirstItem,LastItem);
DoubleSpc=0;
MenuItem1.Flags=CHECKIT+ITEMTEXT+COMMSEQ+MENUTOGGLE+ITEMENABLED+HIGHCOMP;
SubItems[StartingLevel]->Flags-=CHECKED; /*Restore StartingLevel to 0*/
StartingLevel=0;
SubItems[0]->Flags+=CHECKED;
FirstItem=LastItem=FirstScrnItem=ScrnBtm=CurrentItem=
(struct LineItem *)AllocMem(sizeof(struct LineItem),MEMF_CLEAR);
CurrentItem->Level=1;
Buffer[0]=0x0c;
WriteConsole(Buffer,1);
PrintItemList(CurrentItem,1);
PlotCursor(MinX(CurrentItem),CurY);
Modified=FALSE;
TitleErrorCancel();
MenuItem1.Flags=CHECKIT+ITEMTEXT+COMMSEQ+MENUTOGGLE+ITEMENABLED+HIGHCOMP;
return(TRUE);
}
/*I think most of these are self explanatory (HandleNew() handles the New*/
/*item in the Project menu, etc.)*/
HandleNew()
{
if(AreYouSure(Window))
{
NewAll();
FileName[0]=NULL; /*Remove default filenames*/
SFileName[0]=NULL;
PDName[0]=NULL;
PFileName[0]=NULL;
TitleErrorCancel();
}
}
HandleOpen()
{
if(GetFilename(SFileName,SDirName,SExt,FileName,24,9,
"Enter filename for open",Screen,FP,DP,TRUE))
{
if(Modified)
if(!AreYouSure(Window))
return(FALSE);
if(ReadItemList(FileName))
{
Modified=FALSE;
TitleErrorCancel(); /*Write current filename in Title bar*/
} /*if there was no error*/
}
}
Save()
{
if(FileName[0]==NULL)
HandleSaveAs();
else
{
WriteItemList(FileName);
Modified=FALSE;
TitleErrorCancel();
}
}
HandleSaveAs()
{
if(GetFilename(SFileName,SDirName,SExt,FileName,24,9,
"Enter filename for save",Screen,FP,DP,TRUE))
{
if(WriteItemList(FileName))
{
Modified=FALSE;
TitleErrorCancel(); /*Update filename in title bar*/
} /*if there was no error*/
}
}
HandlePrintDisk()
{
struct FileHandle *fp;
char *buffer;
struct LineItem *Item;
if(!GetFilename(PFileName,PDirName,PExt,PDName,24,9,
"Enter filename for print",Screen,FP,DP,TRUE))
return(FALSE);
if((fp=(struct FileHandle *)Open(PDName,MODE_NEWFILE))==NULL)
{
TitleError("Can't open file!");
return(FALSE);
}
buffer=(char *)AllocMem(90,MEMF_CHIP|MEMF_CLEAR);
Item=(struct LineItem *)FirstItem;
while(Item != NULL)
{
strcpy(buffer,"");
GetOutlineChars(Item,buffer);
strcat(buffer," ");
strcat(buffer,Item->Text);
Write(fp,&buffer[Indent],strlen(&buffer[Indent]));
buffer[0]=0x0a;
Write(fp,buffer,1);
if(DoubleSpc)
Write(fp,buffer,1); /*If double spaced, print another RETURN*/
Item=(struct LineItem *)Item->NextItem;
}
FreeMem(buffer,90);
Close(fp);
return(TRUE);
}
HandlePrintPrinter()
{
struct FileHandle *fp;
char *buffer,RetBuf[5],Printed=0;
struct LineItem *Item;
if((fp=(struct FileHandle *)Open("prt:",MODE_OLDFILE))==NULL)
{
TitleError("Can't open printer!");
return(FALSE);
}
buffer=(char *)AllocMem(90,MEMF_CHIP|MEMF_CLEAR);
RetBuf[0]=0x0d;
RetBuf[1]=0x0a;
if(DoubleSpc)
{
RetBuf[2]=0x0d;
RetBuf[3]=0x0a;
RetBuf[4]=0;
}
else
RetBuf[2]=0;
Item=(struct LineItem *)FirstItem;
while(Item != NULL)
{
for(Printed=0;Printed < 60 && Item != NULL;Printed+=(1+DoubleSpc))
{
strcpy(buffer,"");
GetOutlineChars(Item,buffer);
strcat(buffer," ");
strcat(buffer,Item->Text);
Write(fp,&buffer[Indent],strlen(&buffer[Indent]));
strcpy(buffer,RetBuf);
Write(fp,buffer,strlen(buffer));
Item=(struct LineItem *)Item->NextItem;
}
buffer[0]=NEWPAGE;
Write(fp,buffer,1);
}
FreeMem(buffer,90);
Close(fp);
return(TRUE);
}
HandleAbout()
{
int ctr;
struct Window *AboutWdw;
/*Get chip memory for the gadget image.*/
if((ImageData1Chip=(USHORT *)AllocMem(420,MEMF_CHIP|MEMF_CLEAR))==NULL)
return(FALSE);
for(ctr=0;ctr<210;ctr++) /*Transfer image info into chip memory*/
{
ImageData1Chip[ctr]=ImageData1[ctr];
}
/*Do the same for the reversed image*/
if((ImageData2Chip=(USHORT *)AllocMem(840,MEMF_CHIP|MEMF_CLEAR))==NULL)
return(FALSE);
for(ctr=0;ctr<420;ctr++) /*Transfer image info into chip memory*/
{
ImageData2Chip[ctr]=ImageData2[ctr];
}
NewAboutWindow.Screen=Screen; /*Pointer to window's screen*/
Image1.ImageData=(USHORT *)ImageData1Chip;
Image2.ImageData=(USHORT *)ImageData2Chip;
if(Laced)
NewAboutWindow.TopEdge=ABOUT_Y_LACED;
else
NewAboutWindow.TopEdge=ABOUT_Y_REG;
if((AboutWdw=(struct Window *)OpenWindow(&NewAboutWindow))==NULL)
{ /*Open the window*/
FreeMem(ImageData1Chip,420);
FreeMem(ImageData2Chip,840);
return(FALSE);
}
SetWindowTitles(AboutWdw,-1,"For your information...");
SetAPen(AboutWdw->RPort,1);
PrintIText(AboutWdw->RPort,&IntuiTextList2,0,0);
/*Wait for the user to press the Continue... gadget*/
Wait(1<<AboutWdw->UserPort->mp_SigBit);
CloseWindow(AboutWdw); /*Close the window*/
FreeMem(ImageData1Chip,420);
FreeMem(ImageData2Chip,840);
}
HandleQuit()
{
if(Modified) /*Ask "Are you sure?" only if outline isn't saved*/
{
if(AreYouSure(Window))
CloseStuff();
}
else
CloseStuff();
}
HandleCut()
{
if(NOINV==InvsMode)
return(FALSE);
CheckModified();
HandleCopy();
HandleErase();
}
HandleCopy()
{
if(ClipMode < NOINV)
FreeListMem(ClipStart,ClipEnd);
ClipMode=InvsMode;
if(InvsMode > NOINV)
if(StartChar < EndChar)
WriteInvsTextToClip(StartChar,EndChar-StartChar+1,CurrentItem->Text);
else
WriteInvsTextToClip(EndChar,StartChar-EndChar+1,CurrentItem->Text);
else
if(InvsMode == BLOCK_DOWN)
SnagBlock(StartIItem,EndIItem);
else
SnagBlock(EndIItem,StartIItem);
}
HandlePaste()
{
int TempX;
CheckModified();
if(ClipMode < NOINV)
AddBlock(CurrentItem);
else
{
ReadItemString(PosInText(CurrentItem->Level),
79-PosInText(CurrentItem->Level),CurrentItem->Text);
CurrentItem->Text[MaxLen(CurrentItem->Level)]=NULL;
TempX=CurX;
PlotCursor(1,CurY);
PrintItem(CurrentItem);
PlotCursor(TempX,CurY);
}
}
HandleErase()
{
if(InvsMode==NOINV)
return(FALSE);
CheckModified();
if(InvsMode > NOINV)
DelTextBlock();
else
HandleDelBlock();
InvsMode=NOINV;
}
DoubleSpacing()
{
CheckModified();
DoubleSpc=DoubleSpc ^ 1; /*XOR DoubleSpc w/1 to toggle between*/
} /*true and false*/
HandleInterlaced() /*Toggle between normal and interlaced screen*/
{
UBYTE X,Y;
X=CurX;
Y=CurY; /*Store cursor position*/
CloseGraphics();
if(Laced) /*If interlaced*/
{
NewScreen.Height=200;
NewWindow.Height-=200;
NewScreen.ViewModes=HIRES; /*Remove LACE from screen description*/
SCRNHEIGHT-=25; /*Rows*/
Laced=FALSE; /*Status switch*/
}
else /*not interlaced*/
{
NewScreen.Height=400;
NewWindow.Height+=200;
NewScreen.ViewModes=HIRES+LACE; /*Add LACE to screen description*/
SCRNHEIGHT+=25; /*Rows*/
Laced=TRUE;
}
OpenGraphics();
PrintItemList(FirstScrnItem,1);
if(Y > DispRows) /*if the old laced Y is > the current possible rows*/
{
Y=DispRows; /*Y now = the last screen item*/
CurrentItem=(struct LineItem *)ScrnBtm;
}
if(X > MaxX(CurrentItem)) /*Out of bounds*/
X=MaxX(CurrentItem);
else if(X < MinX(CurrentItem))
X=MinX(CurrentItem);
PlotCursor(X,Y); /*Restore cursor position*/
}
HandleFirst() /*Handle 'Starting Level' menu item*/
{
CheckModified();
StartingLevel=0;
Refresh();
}
HandleSecond()
{
CheckModified();
StartingLevel=1;
Refresh();
}
HandleThird()
{
CheckModified();
StartingLevel=2;
Refresh();
}
HandleFourth()
{
CheckModified();
StartingLevel=3;
Refresh();
}
HandleFifth()
{
CheckModified();
StartingLevel=4;
Refresh();
}
HandleSixth()
{
CheckModified();
StartingLevel=5;
Refresh();
}
Refresh()
{
UBYTE OldX,OldY;
OldX=CurX;
OldY=CurY;
PrintItemList(FirstScrnItem,1);
if(OldX < MinX(CurrentItem))
OldX=MinX(CurrentItem);
else
if(OldX > MaxX(CurrentItem))
OldX=MaxX(CurrentItem);
PlotCursor(OldX,OldY);
}
CheckModified()
{
if(Modified==FALSE)
{
Modified=TRUE;
TitleErrorCancel();
}
}